const { ListToNode, NodeToList, ListNode, timeL } = require("../utils.js");
/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var permuteUnique = function (nums) {
  const res = [];
  const fun = (nums, arr = []) => {
    if (!nums.length) {
      res.push(arr.join("-"));
      return;
    }
    for (let i = 0; i < nums.length; i++) {
      const list = [...nums.slice(0, i), ...nums.slice(i + 1)];
      fun(list, [...arr, nums[i]]);
    }
  };
  fun(nums);
  return [...new Set(res)].map((item) => {
    return item.split("-").map((item) => +item);
  });
};
let nums = [1, 1, 2];

timeL(permuteUnique, [nums]);
